package com.heaven.oj.judge;

import com.heaven.oj.judge.strategy.DefaultJudgeStrategy;
import com.heaven.oj.judge.strategy.JavaLanguageJudgeStrategy;
import com.heaven.oj.judge.strategy.JudgeContext;
import com.heaven.oj.judge.strategy.JudgeStrategy;
import com.heaven.oj.judge.CodeSandbox.model.JudgeInfo;
import com.heaven.oj.model.entity.QuestionSubmit;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @Description 判题管理简化调用
 * @Author HeavenDirt
 * @Date 2024/7/25 9:53
 */
@Service
@Slf4j
public class JudgeManager {
    /**
     *执行判题
     * @param judgeContext 入参
     * @return JudgeInfo
     * @author HeavenDirt
     * @date 2024/7/24 15:42
     */
    JudgeInfo doJudge(JudgeContext judgeContext){
        QuestionSubmit questionSubmit = judgeContext.getQuestionSubmit();
        String language = questionSubmit.getLanguage();
        JudgeStrategy judgeStrategy = new DefaultJudgeStrategy();
        if("java".equals(language)){
            judgeStrategy = new JavaLanguageJudgeStrategy();
        }
        log.info("doJudge: language: {}, judgeContext: {}", language, judgeContext);
        return judgeStrategy.doJudge(judgeContext);
    }
}
